/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.qdu.servlet;

import com.qdu.entity.User;
import com.qdu.service.UserService;
import com.qdu.service.impl.UserServiceImpl;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Sanshi
 */

public class ResetPwdBtCode extends HttpServlet {

       private UserService us = new UserServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  //接收用户请求，封装成对象
            String resetCode = request.getParameter("resetCode");
            String  newPassword = request.getParameter("newPassword");
            User User = new User(resetCode, newPassword);
            boolean resetUser = us.resetPwd(User);
             if (resetUser) {
            //注册成功，返回成功页面，重定向
             request.setAttribute("message", "修改成功！");
            request.getRequestDispatcher("/userLog.jsp").forward(request, response);

        } else {
            request.setAttribute("message", "修改失败！请输入正确的密钥");
           request.getRequestDispatcher("/resetPwdEnd.jsp").forward(request, response);
           
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
